package com.example.permissionserviceconsumer.controller;

import com.example.permissionserviceconsumer.service.FeignPermissionService;

import com.myprojects.common.dto.Msg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller
public class PermissionController {

    @Autowired
    FeignPermissionService feignPermissionService;

    /**
     * 该方法用于通过用户id来查询用户拥有的所有资源(权限)
     */
    @RequestMapping(value = "/perm",method = RequestMethod.GET)
    @ResponseBody
    public Msg getUserByToken(@RequestHeader(value = "accessToken") String accessToke){
        return feignPermissionService.getUserByToken(accessToke);
    }

//    /**
//     * 该方法需配合网关模块使用，该方法通过用户请求和token来检查用户拥有的所有资源(权限)
//     */
//    @RequestMapping(value = "/check-request", method = RequestMethod.POST)
//    @ResponseBody
//    public boolean checkUserRequest(@RequestHeader(value = "accessToken") String accessToken,
//                                    @RequestBody String requestURI) {
//        return feignPermissionService.checkUserRequest(accessToken,requestURI);
//    }
}
